<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $guarded = ['key'];
    public function records()
    {
        return $this->hasMany(Record::class);
    }

    public function logs()
    {
        return $this->hasMany(Log::class);
    }

    public function area()
    {
        return $this->belongsTo(Area::class);
    }
    public function warnings()
    {
        return $this->hasMany(Warning::class);
    }

    public function createWarning($code)
    {
        return $this->warnings()->create(['code' => $code]);
    }

    public function createRecord($array)
    {
        unset($array['ie']);
        unset($array['tm']);
        unset($array['key']);
        $array['error'] = $array['ee'];
        unset($array['ee']);
        if (isset($array['ei'])){
            $array['et'] = $array['ei'];
            unset($array['ei']);
        }
        return $this->records()->create($array);
    }
}
